from selenium import webdriver
from selenium.webdriver.common.by import By
import time

driver = webdriver.Chrome()
driver.get("https://www.bing.com")
driver.implicitly_wait(10)

search_window = driver.current_window_handle

driver.find_element(By.LINK_TEXT,"图片").click()
driver.find_element(By.LINK_TEXT,"视频").click()
time.sleep(3)

texts = driver.window_handles
print(len(texts))

for t in texts:
    if t!=search_window:
        driver.switch_to.window(t)
        kw = driver.find_element(By.ID,"sb_form_q")
        kw.clear()
        kw.send_keys("周杰伦")
        kw.submit()

time.sleep(5)

driver.quit()

